//
//  BaseLongLinkService.m
//  Common
//
//  Created by shiqing guo on 2018/10/15.
//  Copyright © 2018年 www.bitkinetic.com. All rights reserved.
//  备注：只所以提取出来一个新的类，是为了便于以后扩展新类

#import "BaseLongLinkService.h"

@implementation BaseLongLinkService

+ (BaseLongLinkModel *)decodeMessage:(id)json
{
    if (![json isKindOfClass:[NSString class]]) return nil;

    BaseLongLinkModel *model = [BaseLongLinkModel mj_objectWithKeyValues:json];
    if ([model.data isKindOfClass:[NSDictionary class]]) {
        model.body = [BaseLongLinkBody mj_objectWithKeyValues:model.data];
    }
    return model;
}


+ (NSString *)encodeWithMsgType:(NSUInteger)msgType andParameter:(NSDictionary *)dic
{
    NSMutableDictionary *mainDic = [[NSMutableDictionary alloc] init];
    [mainDic setObject:@(msgType) forKey:@"Mold"];
    if (dic) [mainDic setObject:dic forKey:@"Body"];
    if ([NSJSONSerialization isValidJSONObject:mainDic]) {
        NSData *data = [NSJSONSerialization dataWithJSONObject:mainDic options:NSJSONWritingPrettyPrinted error:nil];
        NSString *json = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
        return json;
    }
    return nil;
}

@end
